package com.bowlong.bio3;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class B3Test {

	public static void main(String[] args) {
		minMaxIndex();
	}

	public static void test(String[] args) throws IOException {
		List a = new ArrayList();
		a.add(true);
		a.add(false);
		a.add(1);
		a.add(2L);
		a.add("aaa你");

		Set set = new HashSet();
		set.add("1000");
		set.add(1000);
		set.add("哈哈哈");
		a.add(set);

		Map<Object, Object> map = new HashMap<>();
		map.put("k1", "val1");
		map.put(true, false);
		map.put("nil", null);
		map.put("list", a);

		int[] int_arr = { 0, 1, 3, 4 };
		map.put("int_arr", int_arr);

		String[] str_arr = { "a", "b", "c", null, "d" };
		map.put("str_arr", str_arr);
		map.put("dat", new Date());
		map.put("bit", (byte) 8);
		map.put("float", 3.14);
		map.put("buf", "abc".getBytes());

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		B3OutputStream b3out = new B3OutputStream(baos);
		b3out.writeObject(map);
		System.out.println(b3out.ptr());
		System.out.println(baos.toByteArray().length);

		ByteArrayInputStream in = new ByteArrayInputStream(baos.toByteArray());
		B3InputStream b3in = new B3InputStream(in);
		Map v = b3in.readMap();
		System.out.println(v);
		String[] str_arr2 = (String[]) v.get("str_arr");
		System.out.println(Arrays.toString(str_arr2));
	}

	public static void minMaxIndex() {
		int index1 = (byte) B3Types.NULL.ordinal();
		System.out.println(index1);
		int index2 = (byte) B3Types.STR_ARRAY.ordinal();
		System.out.println(index2);
	}
}
